//------------------------------------------------
//		main.c
//	PWM Example
//	Arthur Benemann 13/11/2010
//------------------------------------------------
//	Description:
//  A Led Blinker, using the PWM library.
//------------------------------------------------

#include "picDev.h"       // Hardware Definitions
#include "PWM/PWM1.h"       // PWM library
#include "DELAY/DELAY.h"    // Delay library
#include "math.h"           // Math library, used for the sine function

#define PI 3.1415

//-------------------- Main -----------------------
int main() {
    int a=128,duty;

    initPWM1(255,128);      // Initialize the PWM module

    // Main loop
    while (1) {
        duty = 128+128*sin(a*2*PI/255); // Calculate the sine value at this step
        writePWM1(duty);                // Sends the PWM value
        delayms(10);                    // Loop delay
        if(a++>255)                     // Increments the loop counter and
            a=0;                        // Test if it has completed a sine period
    };
}



